/**
 * 
 */
package org.youisoft.summer.evaluator.function.ext;


import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.function.AbstractFunction;
import org.youisoft.summer.evaluator.operator.Operator;
import org.youisoft.summer.evaluator.operator.base.NumberOperator;

/**
 * @author zijiang.jl
 *
 */
public class RoundFunction extends AbstractFunction{

	private static final java.util.List<Class<?>> supports;
	static{
		supports=new java.util.ArrayList<Class<?>>();
		supports.add(NumberOperator.class);
	}

	@Override
	public String getName() {
		return "round";
	}
	
	@Override
	protected boolean checkOperator(int index, Operator<?> operator) {
		return supports.contains(operator.getClass());
	}

	@Override
	public <C,R,P> Operator<?> doInvoke(CalContext<C,R,P> context,Operator<?>... operator) {
		NumberOperator d=(NumberOperator)operator[0];
		d.setValue(java.lang.StrictMath.round(d.value().doubleValue()));
		return d;
	}
	
	@Override
	protected int minOperatorCount() {
		return 1;
	}
}
